<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>IRC（Internet Relay Chat）（因特网中继聊天）协议——RFC1459文档要点总结 | 夜悊的技术小宅</title><meta name="author" content="夜悊"><meta name="copyright" content="夜悊"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="前言IRC（Internet Relay Chat）（因特网中继聊天）协议是由芬兰人Jarkko Oikarinen于1988年首创的一种网络聊天协议。文章对“RFC 1459 - Internet Relay Chat Protocol”文档要点进行总结。  特点 基于文本   “文本”：因为应用的功能是“聊天”，传输的数据类型是“文本文字”   最简单的客户机是任何能够连接到服务器的套接字程序">
<meta property="og:type" content="article">
<meta property="og:title" content="IRC（Internet Relay Chat）（因特网中继聊天）协议——RFC1459文档要点总结">
<meta property="og:url" content="http://example.com/2022/04/16/IRC%EF%BC%88Internet%20Relay%20Chat%EF%BC%89%EF%BC%88%E5%9B%A0%E7%89%B9%E7%BD%91%E4%B8%AD%E7%BB%A7%E8%81%8A%E5%A4%A9%EF%BC%89%E5%8D%8F%E8%AE%AE%E2%80%94%E2%80%94RFC1459%E6%96%87%E6%A1%A3%E8%A6%81%E7%82%B9%E6%80%BB%E7%BB%93/index.html">
<meta property="og:site_name" content="夜悊的技术小宅">
<meta property="og:description" content="前言IRC（Internet Relay Chat）（因特网中继聊天）协议是由芬兰人Jarkko Oikarinen于1988年首创的一种网络聊天协议。文章对“RFC 1459 - Internet Relay Chat Protocol”文档要点进行总结。  特点 基于文本   “文本”：因为应用的功能是“聊天”，传输的数据类型是“文本文字”   最简单的客户机是任何能够连接到服务器的套接字程序">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/img/cover4.png">
<meta property="article:published_time" content="2022-04-16T09:18:18.000Z">
<meta property="article:modified_time" content="2023-05-22T02:50:53.359Z">
<meta property="article:author" content="夜悊">
<meta property="article:tag" content="环境和网络编程">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/img/cover4.png"><link rel="shortcut icon" href="/img/favicon2.png"><link rel="canonical" href="http://example.com/2022/04/16/IRC%EF%BC%88Internet%20Relay%20Chat%EF%BC%89%EF%BC%88%E5%9B%A0%E7%89%B9%E7%BD%91%E4%B8%AD%E7%BB%A7%E8%81%8A%E5%A4%A9%EF%BC%89%E5%8D%8F%E8%AE%AE%E2%80%94%E2%80%94RFC1459%E6%96%87%E6%A1%A3%E8%A6%81%E7%82%B9%E6%80%BB%E7%BB%93/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css?v=4.13.0"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.33/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: 夜悊","link":"链接: ","source":"来源: 夜悊的技术小宅","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid@4.11.1/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'IRC（Internet Relay Chat）（因特网中继聊天）协议——RFC1459文档要点总结',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-05-22 10:50:53'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><link rel="stylesheet" href="/css/my_css.css"><meta name="generator" content="Hexo 7.3.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">92</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">15</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">15</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-bookmark"></i><span> 笔记目录</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-blog"></i><span> 其他博客</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://blog.csdn.net/m0_62083249"><i class="fa-fw fa fa-link"></i><span> CSDN</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.zhihu.com/people/ye-zhe-ning"><i class="fa-fw fa fa-link"></i><span> 知乎</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-sitemap"></i><span> 代码仓库</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://gitee.com/yezhening"><i class="fa-fw fa fa-link"></i><span> Gitee</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://github.com/yezhening"><i class="fa-fw fa fa-link"></i><span> Github</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about_me/"><i class="fa-fw fas fa-user"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/cover4.png')"><nav id="nav"><span id="blog-info"><a href="/" title="夜悊的技术小宅"><span class="site-name">夜悊的技术小宅</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-bookmark"></i><span> 笔记目录</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-blog"></i><span> 其他博客</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://blog.csdn.net/m0_62083249"><i class="fa-fw fa fa-link"></i><span> CSDN</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.zhihu.com/people/ye-zhe-ning"><i class="fa-fw fa fa-link"></i><span> 知乎</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw fa fa-sitemap"></i><span> 代码仓库</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://gitee.com/yezhening"><i class="fa-fw fa fa-link"></i><span> Gitee</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://github.com/yezhening"><i class="fa-fw fa fa-link"></i><span> Github</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about_me/"><i class="fa-fw fas fa-user"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">IRC（Internet Relay Chat）（因特网中继聊天）协议——RFC1459文档要点总结</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-04-16T09:18:18.000Z" title="发表于 2022-04-16 17:18:18">2022-04-16</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-05-22T02:50:53.359Z" title="更新于 2023-05-22 10:50:53">2023-05-22</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E7%8E%AF%E5%A2%83%E5%92%8C%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/">环境和网络编程</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="IRC（Internet Relay Chat）（因特网中继聊天）协议——RFC1459文档要点总结"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>IRC（Internet Relay Chat）（因特网中继聊天）协议是由芬兰人Jarkko Oikarinen于1988年首创的一种网络聊天协议。文章对“RFC 1459 - Internet Relay Chat Protocol”文档要点进行总结。</p>
<hr>
<h1 id="特点"><a href="#特点" class="headerlink" title="特点"></a>特点</h1><ul>
<li>基于文本</li>
</ul>
<blockquote>
<p>“文本”：因为应用的功能是“聊天”，传输的数据类型是“文本文字”</p>
</blockquote>
<ul>
<li><strong>最简单的</strong>客户机是任何能够连接到服务器的套接字程序</li>
<li>使用TCP&#x2F;IP网络协议</li>
<li>依据客户机-服务器模型</li>
<li>典型的设置包括单个进程(服务器)形成客户机(或其他服务器)连接的中心点，执行所需的消息传递&#x2F;多路复用和其他功能。如图：</li>
</ul>
<blockquote>
<p>提示：类比树状网络</p>
</blockquote>
<p><img src= "" data-lazy-src="/../img/irc/cc0e700f6dc64ce3a5671216b67d9d36.png"></p>
<hr>
<h1 id="三种角色"><a href="#三种角色" class="headerlink" title="三种角色"></a>三种角色</h1><ul>
<li>服务器</li>
<li>客户机</li>
<li>运营商（特殊类别的客户，类比管理员）</li>
</ul>
<hr>
<h1 id="信道-频道"><a href="#信道-频道" class="headerlink" title="信道&#x2F;频道"></a>信道&#x2F;频道</h1><ul>
<li><strong>信道是由一个或多个客户端组成的命名组，这些客户端将接收到发送给该信道的消息</strong>。当第一个客户端加入信道时，信道隐式地创建，当最后一个客户端离开信道时，信道停止存在。当信道存在时，任何客户端都可以使用信道名引用信道。</li>
</ul>
<blockquote>
<p>“信道是由一个或多个客户端组成的命名组，这些客户端将接收到发送给该信道的消息”：信道是一个或多个客户端的集合，即“聊天群”。在同一个“聊天群”内，客户端可接收到其他（0、1或多个）客户端的消息</p>
</blockquote>
<ul>
<li>协议存在两种类型的信道。一种是<strong>分布式</strong>信道，<strong>所有的</strong>服务器都知道它（们）</li>
<li>要创建新信道或成为现有信道的一部分，需要用户加入该信道。如果信道在加入之前不存在，则创建信道，创建信道的用户成为信道操作符。如果信道已经存在，那么加入请求是否被接受取决于该信道的当前模式。例如，如果该信道只接受邀请，则用户只能在被邀请时加入</li>
</ul>
<blockquote>
<p>“信道操作符”：即“信道标识符”、“聊天群群主&#x2F;管理员”</p>
</blockquote>
<ul>
<li>一个用户可能同时属于多个信道的一部分</li>
</ul>
<hr>
<h1 id="字符编码"><a href="#字符编码" class="headerlink" title="字符编码"></a>字符编码</h1><p>没有为文本的字符数据类型指定特定的字符集。<strong>协议</strong>基于一系列由8位组成的代码（八位组&#x2F;字节）。每条消息可以由任意数量的字节构成。</p>
<blockquote>
<p>“协议”：原文档内容是：“ The protocol is based on a …”。表意不太明确。在编程实现时，可以简化理解为“<strong>每字符</strong>”基于一个字节，而“char”数据类型大小刚好为一个字节</p>
</blockquote>
<hr>
<h1 id="消息传递方式"><a href="#消息传递方式" class="headerlink" title="消息传递方式"></a>消息传递方式</h1><ul>
<li>客户机-服务器和服务器-服务器之间的通信是异步的</li>
<li>消息传递图类比网络拓扑图：</li>
</ul>
<p><img src= "" data-lazy-src="/../img/irc/27e8c7d5aaad4b92aeee0902a22e7bf2.png"></p>
<h2 id="一对一通信"><a href="#一对一通信" class="headerlink" title="一对一通信"></a>一对一通信</h2><ul>
<li>通常只在客户端间进行一对一通信，因为大多数服务器-服务器通信<strong>都不是</strong>服务器之间<strong>只进行通信</strong>的结果。理由见后面“一对所有通信”内容</li>
<li>消息传递的路径是生成树上任意两点之间的<strong>最短</strong>路径</li>
</ul>
<blockquote>
<p>“最短路径”：即“最低开销”路径，在<strong>尽可能少的</strong>客户机、服务器间传递消息</p>
</blockquote>
<p>示例1:<br>客户机1和客户机2之间的消息只被服务器A知道，服务器A将客户机1的消息直接发送给客户机2。</p>
<p>示例2:<br>客户机1和3之间的消息能够被服务器A和B知道。其他客户机、服务器不能知道该消息。</p>
<p>示例3:<br>客户机2和4之间的消息能够被服务器A、B、C和D知道。</p>
<h2 id="一对多通信"><a href="#一对多通信" class="headerlink" title="一对多通信"></a>一对多通信</h2><ul>
<li>三种通信方式：消息列表、信道&#x2F;群组和客户机、服务器掩码</li>
<li>消息列表：客户机提供消息要传递到的目的地的列表，服务器分解列表，依据列表项，将消息的各单独副本分发到每个给定的目的地</li>
<li>信道&#x2F;群组：客户机的消息只发送到服务器一次，服务器将消息发送到信道中的每个客户机。然后对每个服务器-客户机对重复此操作，直到原始消息呈扇形传播并到达通道中的每个服务器、客户机</li>
</ul>
<blockquote>
<p>提示：类比网络传输的“多播”进行理解</p>
</blockquote>
<ul>
<li>客户机、服务器掩码：通过“掩码消息”，将消息传递给指定的服务器、客户机</li>
</ul>
<h2 id="一对所有通信"><a href="#一对所有通信" class="headerlink" title="一对所有通信"></a>一对所有通信</h2><ul>
<li>客户机到客户机：无</li>
<li>客户机到服务器：客户机的大多数导致状态信息改变的命令(如信道成员、信道模式、用户状态等)在默认情况下必须发送到所有服务器</li>
<li>服务器到服务器：几乎所有来自服务器的消息都会广播到所有其他连接的服务器</li>
</ul>
<hr>
<h1 id="命令"><a href="#命令" class="headerlink" title="命令"></a>命令</h1><p>略</p>
<hr>
<h1 id="当前实现内容"><a href="#当前实现内容" class="headerlink" title="当前实现内容"></a>当前实现内容</h1><blockquote>
<p>“当前实现内容”：原文档标题是：“Current implementations”。描述的是当前IRC协议的实现细节</p>
</blockquote>
<h2 id="基于TCP网络协议"><a href="#基于TCP网络协议" class="headerlink" title="基于TCP网络协议"></a>基于TCP网络协议</h2><p>TCP是可靠的网络协议，适合于IRC协议的“<strong>一定规模文本数据交互</strong>”内容。</p>
<h2 id="支持Unix域套接字"><a href="#支持Unix域套接字" class="headerlink" title="支持Unix域套接字"></a>支持Unix域套接字</h2><p>鉴于Unix域套接字是监听&#x2F;连接操作，<strong>可以将当前实现配置为</strong>：监听和接受Unix域套接字上的客户机和服务器连接。</p>
<blockquote>
<p>“可以将当前实现配置为…”：即可使用套接字API（应用程序编程接口）进行网络编程实现IRC协议</p>
</blockquote>
<h2 id="命令解析"><a href="#命令解析" class="headerlink" title="命令解析"></a>命令解析</h2><p><strong>每个网络连接都有私有的“输入缓冲区”</strong>，其中保存<strong>最近的</strong>读取和解析<strong>命令</strong>结果。缓冲区设置的目的是为客户机和服务器提供有用的“<strong>非缓冲</strong>”网络IO。</p>
<blockquote>
<p>“每个网络连接都有私有的“输入缓冲区”：原文档内容是“each connection is given its own private ‘input buffer…”。结合上下文理解：一般是客户机给服务器发送“命令”消息，又是“输入”缓冲区，则该“缓冲区”应在每客户机-服务器连接对的客户机一端</p>
</blockquote>
<blockquote>
<p>“最近的”：缓冲区可能存储多个命令与解析结果</p>
</blockquote>
<blockquote>
<p>“非缓冲”：原文档内容是“ To provide useful ‘non-buffered’ network IO…”。描述上，其是具有缓冲区的，这里的意思可能是：“异步”网络IO：在缓冲区<strong>缓冲地</strong>存放命令和解析结果，由客户机、服务器<strong>异步地</strong>获取相应内容。编程实现时，可以考虑使用异步IO：“io_uring”技术</p>
</blockquote>
<h2 id="消息队列机制"><a href="#消息队列机制" class="headerlink" title="消息队列机制"></a>消息队列机制</h2><ul>
<li>为缓解“网络连接饱和”，使用TCP窗口、内部缓冲区和消息队列机制</li>
</ul>
<blockquote>
<p>“TCP窗口”：原文档内容：“Although Unix typically handles this through the TCP window and internal buffers…”。这里指的是TCP流量控制而不是拥塞控制内容，即缓解“收发数据<strong>两端</strong>流量速率不匹配问题”</p>
</blockquote>
<ul>
<li>消息队列机制：FIFO（先进先出）数据发送队列。<strong>服务器轮询它的连接时</strong>，首先读取并解析所有传入的数据，将所有<strong>要发送出去的</strong>数据排在队列中。处理完所有可用的输入后，发送排队的数据。能够<strong>减少write()系统调用的数量</strong>，并帮助TCP生成更大的包</li>
</ul>
<blockquote>
<p>“服务器轮询它的连接时”：一台服务器可能有多个“服务器-服务器”、“服务器-客户机”连接对，服务器需要依次处理消息</p>
</blockquote>
<blockquote>
<p>“能够减少write()系统调用的数量”：编程实现时，可以考虑使用“io_uring”技术，它的优势之一亦是减少系统调用的次数，降低系统开销</p>
</blockquote>
<hr>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>IRC（Internet Relay Chat）（因特网中继聊天）协议是基于TCP&#x2F;IP的应用层协议，工作原理简单，能够通过网络编程：使用套接字API+“客户机-服务器”模型+其他技术实现。</p>
<hr>
<h1 id="作者的话"><a href="#作者的话" class="headerlink" title="作者的话"></a>作者的话</h1><ul>
<li>文章内容是作者为完成一项“基于C&#x2F;C++语言、异步IO：‘io_uring’技术的IRC协议实现”的网络编程小程序，通篇翻译、阅读“RFC 1459 - Internet Relay Chat Protocol”文档进行的要点总结。选取的内容基于<strong>作者认为</strong>对编程实现重要的点，描述并不全面，具体请参阅其他资料</li>
<li>文章在描述时有疑惑的地方，请留言，定会一一耐心讨论、解答</li>
<li>文章在认识上有错误的地方, 敬请批评指正</li>
<li>望读者们都能有所收获</li>
</ul>
<hr>
<h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><p><a target="_blank" rel="noopener" href="http://www.faqs.org/rfcs/rfc1459.html">RFC 1459 - Internet Relay Chat Protocol</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="http://example.com">夜悊</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2022/04/16/IRC%EF%BC%88Internet%20Relay%20Chat%EF%BC%89%EF%BC%88%E5%9B%A0%E7%89%B9%E7%BD%91%E4%B8%AD%E7%BB%A7%E8%81%8A%E5%A4%A9%EF%BC%89%E5%8D%8F%E8%AE%AE%E2%80%94%E2%80%94RFC1459%E6%96%87%E6%A1%A3%E8%A6%81%E7%82%B9%E6%80%BB%E7%BB%93/">http://example.com/2022/04/16/IRC（Internet Relay Chat）（因特网中继聊天）协议——RFC1459文档要点总结/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">夜悊的技术小宅</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E7%8E%AF%E5%A2%83%E5%92%8C%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/">环境和网络编程</a></div><div class="post_share"><div class="social-share" data-image="/img/cover4.png" data-sites="qq,wechat,weibo"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.3/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.3/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2022/04/15/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E6%80%9D%E6%83%B3/" title="面向对象思想"><img class="cover" src= "" data-lazy-src="/img/cover4.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">面向对象思想</div></div></a></div><div class="next-post pull-right"><a href="/2022/04/17/%E6%8C%87%E9%92%88%E3%80%81%E5%BC%95%E7%94%A8%E5%92%8C%E5%B8%B8%E9%87%8F%E7%9A%84%E5%85%B3%E7%B3%BB/" title="指针、引用和常量的关系"><img class="cover" src= "" data-lazy-src="/img/cover11.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">指针、引用和常量的关系</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2023/10/25/%E7%8E%AF%E5%A2%83%E7%BC%96%E7%A8%8B%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B%EF%BC%9A%E2%80%9C%E5%8A%A0_%E5%8D%B8%E8%BD%BD%E2%80%9D%20Zend%20Framework%202/" title="环境编程代码实例：“加&#x2F;卸载” Zend Framework 2"><img class="cover" src= "" data-lazy-src="/img/cover10.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-10-25</div><div class="title">环境编程代码实例：“加&#x2F;卸载” Zend Framework 2</div></div></a></div><div><a href="/2023/05/16/%E7%8E%AF%E5%A2%83%E7%BC%96%E7%A8%8B%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B%EF%BC%9A%E8%BF%9B%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1%EF%BC%88IPC%EF%BC%89/" title="环境编程代码实例：进程间通信（IPC）"><img class="cover" src= "" data-lazy-src="/img/cover3.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-05-16</div><div class="title">环境编程代码实例：进程间通信（IPC）</div></div></a></div><div><a href="/2023/05/01/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B%EF%BC%9AIO%E5%A4%8D%E7%94%A8%E7%89%88/" title="网络编程代码实例：IO复用版"><img class="cover" src= "" data-lazy-src="/img/cover16.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-05-01</div><div class="title">网络编程代码实例：IO复用版</div></div></a></div><div><a href="/2023/04/24/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B%EF%BC%9A%E4%BC%A0%E8%BE%93%E6%8E%A7%E5%88%B6%E5%8D%8F%E8%AE%AE%EF%BC%88TCP%EF%BC%89%E7%AE%80%E5%8D%95%E7%89%88/" title="网络编程代码实例：传输控制协议（TCP）简单版"><img class="cover" src= "" data-lazy-src="/img/cover19.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-04-24</div><div class="title">网络编程代码实例：传输控制协议（TCP）简单版</div></div></a></div><div><a href="/2023/04/26/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B%EF%BC%9A%E5%A4%9A%E8%BF%9B%E7%A8%8B%E7%89%88/" title="网络编程代码实例：多进程版"><img class="cover" src= "" data-lazy-src="/img/cover11.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-04-26</div><div class="title">网络编程代码实例：多进程版</div></div></a></div><div><a href="/2023/04/25/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E4%BB%A3%E7%A0%81%E5%AE%9E%E4%BE%8B%EF%BC%9A%E7%94%A8%E6%88%B7%E6%95%B0%E6%8D%AE%E6%8A%A5%E5%8D%8F%E8%AE%AE%EF%BC%88UDP%EF%BC%89%E7%AE%80%E5%8D%95%E7%89%88/" title="网络编程代码实例：用户数据报协议（UDP）简单版"><img class="cover" src= "" data-lazy-src="/img/cover2.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-04-25</div><div class="title">网络编程代码实例：用户数据报协议（UDP）简单版</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%89%B9%E7%82%B9"><span class="toc-number">2.</span> <span class="toc-text">特点</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89%E7%A7%8D%E8%A7%92%E8%89%B2"><span class="toc-number">3.</span> <span class="toc-text">三种角色</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BF%A1%E9%81%93-%E9%A2%91%E9%81%93"><span class="toc-number">4.</span> <span class="toc-text">信道&#x2F;频道</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E7%BC%96%E7%A0%81"><span class="toc-number">5.</span> <span class="toc-text">字符编码</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%B6%88%E6%81%AF%E4%BC%A0%E9%80%92%E6%96%B9%E5%BC%8F"><span class="toc-number">6.</span> <span class="toc-text">消息传递方式</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E5%AF%B9%E4%B8%80%E9%80%9A%E4%BF%A1"><span class="toc-number">6.1.</span> <span class="toc-text">一对一通信</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E5%AF%B9%E5%A4%9A%E9%80%9A%E4%BF%A1"><span class="toc-number">6.2.</span> <span class="toc-text">一对多通信</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E5%AF%B9%E6%89%80%E6%9C%89%E9%80%9A%E4%BF%A1"><span class="toc-number">6.3.</span> <span class="toc-text">一对所有通信</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%91%BD%E4%BB%A4"><span class="toc-number">7.</span> <span class="toc-text">命令</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BD%93%E5%89%8D%E5%AE%9E%E7%8E%B0%E5%86%85%E5%AE%B9"><span class="toc-number">8.</span> <span class="toc-text">当前实现内容</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%BA%E4%BA%8ETCP%E7%BD%91%E7%BB%9C%E5%8D%8F%E8%AE%AE"><span class="toc-number">8.1.</span> <span class="toc-text">基于TCP网络协议</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%94%AF%E6%8C%81Unix%E5%9F%9F%E5%A5%97%E6%8E%A5%E5%AD%97"><span class="toc-number">8.2.</span> <span class="toc-text">支持Unix域套接字</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%91%BD%E4%BB%A4%E8%A7%A3%E6%9E%90"><span class="toc-number">8.3.</span> <span class="toc-text">命令解析</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97%E6%9C%BA%E5%88%B6"><span class="toc-number">8.4.</span> <span class="toc-text">消息队列机制</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">9.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BD%9C%E8%80%85%E7%9A%84%E8%AF%9D"><span class="toc-number">10.</span> <span class="toc-text">作者的话</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99"><span class="toc-number">11.</span> <span class="toc-text">参考资料</span></a></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('/img/cover4.png')"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2025 By 夜悊</div><div class="footer_custom_text"><a target="_blank" href="https://beian.miit.gov.cn/" >琼ICP备2023001225号-1</a><br><img src= "" data-lazy-src="/img/beian.png"/>&nbsp<a target="_blank" href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=46010802001221" >琼公网安备 46010802001221号</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="translateLink" type="button" title="简繁转换">繁</button><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js?v=4.13.0"></script><script src="/js/main.js?v=4.13.0"></script><script src="/js/tw_cn.js?v=4.13.0"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.33/dist/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@17.8.8/dist/lazyload.iife.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js?v=4.13.0"></script></div></div></body></html>